<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" @Launchform="Launchform11" @findClicked="findClicked11" :formList="formList2" />

    <div class="ProductionDynamic">
      <!-- 主体 -->
      <div style="margin-top: 15px" class="ProductionDynamicMain">
        <el-card class="ProductionDynamicMainCard" shadow="always" :body-style="{ padding: '15px' }">
          <div class="ProductionDynamicMainCardMain">
            <div style="width: 50%">
              <h1 class="H1Size">
                楦头资料<el-button type="primary" size="small" @click="dialogVisible2 = true">增</el-button>
                <el-button style="margin-left: 15px" type="primary" size="small" @click="handleCloseMateriaLKlc6">删</el-button>
              </h1>
              <Table
                :isLoading="isLoading"
                @inputChange="checkboxChange1"
                @currentRow="currentRow1"
                :tableData="LastDataQueryTableDate"
                :tableHeader="tableHeader"
                :selection="false"
                :TableHeight="100"
                :outTableHeight="70"
              />
            </div>
            <div style="width: 15%; margin-top: 20px; margin-left: 15px">
              <h1 class="H1Size">
                楦头所用型体
                <el-button style="margin-left: 15px" type="primary" size="small" @click="handleCloseMateriaLKlc8">删</el-button>
              </h1>
              <div>
                <Table
                  :isLoading="isLoading1"
                  @currentRow="currentRow3"
                  @inputChange="checkboxChange2"
                  :tableData="LastStyleQueryTableDate"
                  :tableHeader="tableHeader1"
                  :selection="false"
                  :TableHeight="100"
                  :outTableHeight="70"
                />
              </div>
            </div>
            <div style="width: 13%; margin-top: 20px; margin-left: 15px">
              <h1 class="H1Size">
                楦头号码资料
                <el-button style="margin-left: 15px" type="primary" size="small" @click="handleCloseMateriaLKlc7">删</el-button>
              </h1>
              <div>
                <Table
                  :isLoading="isLoading2"
                  @currentRow="currentRow2"
                  :tableData="SizeQueryMethodsTableDate"
                  :tableHeader="tableHeader2"
                  :selection="false"
                  :TableHeight="100"
                  :outTableHeight="70"
                />
              </div>
            </div>
          </div>
        </el-card>
      </div>
    </div>

    <el-dialog v-model="dialogVisible2" width="50%">
      <Find :OriginalFilter="{ static: true }" @Launchform="Launchform12" @findClicked="findClicked12" :searchImg="false" :formList="formList13" />
    </el-dialog>

    <el-dialog v-model="dialogVisible3" width="50%">
      <Find :OriginalFilter="{ static: true }" :searchImg="false" @Launchform="Launchform1" @findClicked="findClicked" :formList="formList1" />
      <Table
        @currentRow="currentRow5"
        :tableData="styleQueryTableDate"
        :tableHeader="tableHeader3"
        :selection="false"
        :TableHeight="100"
        :outTableHeight="40"
      />
      <PageModule
        :PageData="{ total: totalA, buttonS: true, pageSizeShow: true }"
        :layout="'prev, pager'"
        @pageSizeChange="handleSizeChange1"
        @pageChange="handleCurrentChange1"
      />
    </el-dialog>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'LastInformation'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import {
  styleQuery,
  AddList,
  deleteLastD,
  deleteLast,
  AddLastDataQuery,
  LastDataQuery,
  LastStyleQuery,
  SizeQuery,
  deletLastDataQuery
} from '@/api/Control/FactoryControl/LastInformation'
import LoginWork from '@/utils/LoginWork'
import { ElMessage, ElMessageBox } from 'element-plus'
const isLoading = ref(false)
const isLoading1 = ref(false)
const isLoading2 = ref(false)

// 新增
const AddListParms = ref<any>({
  style: []
})

const findClicked = (count: string) => {
  if (count === '保存') {
    if (AddListParms.value.style.length === 0) {
      JMessage.warning('请选择需要插入的数据')
    } else {
      AddListMethods()
    }
  }
}

const currentRow5 = (row: any) => {
  AddListParms.value.style.push(row.style)
}

const AddListMethods = async () => {
  const result = await AddList(deleteLastDQueryParms.value.lastNo, AddListParms.value.style)
  if (result.code === 200) {
    LastStyleQueryMethods()
    AddListParms.value.style.length = 0
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 型体查询
const HolidayInquiryParms = ref({
  pageNum: 1,
  pageSize: 40
})

const Launchform1 = (row: any) => {
  styleList.value = row[0].inputValue
  styleQueryMethods()
}

const styleList = ref('')

const styleQueryTableDate = ref([])

const styleQueryMethods = async () => {
  const result = await styleQuery(HolidayInquiryParms.value, styleList.value)

  styleQueryTableDate.value = result.dtos.map((item: any) => {
    return { style: item }
  })
  totalA.value = result.total
}

const totalA = ref(0)

const handleSizeChange1 = (val: number) => {
  HolidayInquiryParms.value.pageSize = val
  styleQueryMethods()
}

const handleCurrentChange1 = (val: number) => {
  HolidayInquiryParms.value.pageNum = val
  styleQueryMethods()
}

// 增加
const dialogVisible3 = ref(false)

// 号码删除
const deleteLastDQueryParms = ref({
  lastNo: '',
  style: ''
})

const deleteLastDMethods = async () => {
  const result = await deleteLastD(deleteLastDQueryParms.value)
  if (result.code === 200) {
    LastStyleQueryMethods()
    deleteLastDQueryParms.value.style = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc8 = () => {
  if (deleteLastDQueryParms.value.style === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteLastDMethods()
      })
      .catch(() => {})
  }
}

// 楦头所用型体修改
const checkboxChange2Parms = ref({
  lastNo: '',
  style: ''
})

const styleOldList = ref('')

const currentRow3 = (row: any) => {
  styleOldList.value = row.style
  deleteLastDQueryParms.value.style = row.style
}

const checkboxChange2 = async (list: any) => {
  checkboxChange2Parms.value.style = list.style
  const result = await LoginWork.put<any, any>(`/bioDeptWrok/lastStyleUpdate?styleOld=${styleOldList.value}`, checkboxChange2Parms.value)
  if (result.code === 200) {
    LastStyleQueryMethods()
    JMessage.success(result.message)
  } else {
    LastStyleQueryMethods()
    JMessage.error(result.message)
  }
}

// 号码删除
const deleteLastDataQueryParms = ref({
  lastNo: '',
  seqNo: ''
})

const currentRow2 = (row: any) => {
  deleteLastDataQueryParms.value.seqNo = row.seqNo
}

const deleteLastQueryMethods = async () => {
  console.log(deleteLastDataQueryParms.value)
  const result = await deleteLast(deleteLastDataQueryParms.value)
  if (result.code === 200) {
    SizeQueryMethods()
    deleteLastDataQueryParms.value.seqNo = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc7 = () => {
  if (deleteLastDataQueryParms.value.seqNo === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteLastQueryMethods()
      })
      .catch(() => {})
  }
}

// 增加
const dialogVisible2 = ref(false)

const AddLastDataQueryParms = ref({
  lastNo: '',
  tech1: '',
  tech2: '',
  tech3: '',
  tech4: '',
  tech5: '',
  tech6: '',
  tech7: '',
  tech8: '',
  tech9: ''
})

const AddLastDataQueryMethods = async () => {
  const result = await AddLastDataQuery(AddLastDataQueryParms.value)
  if (result.code === 200) {
    LastDataQueryMethods()
    AddLastDataQueryParms.value.lastNo = ''
    dialogVisible2.value = false
    clearFormList3()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const findClicked12 = (row: any) => {
  if (row === '保存') {
    if (AddLastDataQueryParms.value.lastNo === '') {
      JMessage.warning('楦头号不可为空')
    } else {
      AddLastDataQueryMethods()
    }
  }
  if (row === '置空') {
    clearFormList3()
  }
}

const clearFormList3 = () => {
  formList13.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
  })
}

const Launchform12 = (row: any) => {
  AddLastDataQueryParms.value.lastNo = row[0].inputValue
  AddLastDataQueryParms.value.tech1 = row[1].inputValue
  AddLastDataQueryParms.value.tech2 = row[2].inputValue
  AddLastDataQueryParms.value.tech3 = row[3].inputValue
  AddLastDataQueryParms.value.tech4 = row[4].inputValue
  AddLastDataQueryParms.value.tech5 = row[5].inputValue
  AddLastDataQueryParms.value.tech6 = row[6].inputValue
  AddLastDataQueryParms.value.tech7 = row[7].inputValue
  AddLastDataQueryParms.value.tech8 = row[8].inputValue
  AddLastDataQueryParms.value.tech9 = row[9].inputValue
}

const formList13 = ref([
  {
    type: 'input',
    inputPlaceholder: '楦头',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '鞋垫前后置',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '底长',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '掌宽',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '跟宽',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '掌围',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '腰围',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '背围',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '楦头后跟高',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '楦头头翘',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList1 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'button',
    checkboxLabel: '保存'
  }
])

// 楦头删除
const deletLastDataQueryParms = ref('')

const deletLastDataQueryMethods = async () => {
  const result = await deletLastDataQuery(deletLastDataQueryParms.value)
  if (result.code === 200) {
    LastDataQueryMethods()
    deletLastDataQueryParms.value = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc6 = () => {
  if (deletLastDataQueryParms.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deletLastDataQueryMethods()
      })
      .catch(() => {})
  }
}

// 楦头资料修改
const checkboxChange1 = async (list: any) => {
  const result = await LoginWork.put<any, any>(`/bioDeptWrok/lastInfoUpdate?lastNoOld=${LastStyleQueryParms.value}`, list)
  if (result.code === 200) {
    LastDataQueryMethods()
    JMessage.success(result.message)
  } else {
    LastDataQueryMethods()
    JMessage.error(result.message)
  }
}

const currentRow1 = (row: any) => {
  LastStyleQueryParms.value = row.lastNo
  deletLastDataQueryParms.value = row.lastNo
  deleteLastDataQueryParms.value.lastNo = row.lastNo
  checkboxChange2Parms.value.lastNo = row.lastNo
  deleteLastDQueryParms.value.lastNo = row.lastNo
  LastStyleQueryMethods()
  SizeQueryMethods()
}

// 号码查询
const SizeQueryMethodsTableDate = ref([])

const SizeQueryMethods = async () => {
  isLoading2.value = true
  const result = await SizeQuery(LastStyleQueryParms.value)
  SizeQueryMethodsTableDate.value = result
  isLoading2.value = false
}

// 型体查询
const LastStyleQueryParms = ref('')

const LastStyleQueryTableDate = ref([])

const LastStyleQueryMethods = async () => {
  isLoading1.value = true
  const result = await LastStyleQuery(LastStyleQueryParms.value)
  LastStyleQueryTableDate.value = result.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  isLoading1.value = false
}

const Launchform11 = (row: any) => {
  LastDataQueryParms.value.lastNo = row[0].inputValue
  LastDataQueryParms.value.style = row[1].inputValue
  LastDataQueryMethods()
}

const findClicked11 = (count: string) => {
  switch (count) {
    case '选择型体': {
      dialogVisible3.value = true
      styleQueryMethods()
    }
  }
}

// 楦头资料查询
const LastDataQueryParms = ref({
  lastNo: '',
  style: ''
})

const LastDataQueryTableDate = ref([])

const LastDataQueryMethods = async () => {
  isLoading.value = true
  const result = await LastDataQuery(LastDataQueryParms.value)
  LastDataQueryTableDate.value = result.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  if (result.length > 0) {
    LastStyleQueryParms.value = result[0].lastNo
    deleteLastDataQueryParms.value.lastNo = result[0].lastNo
    checkboxChange2Parms.value.lastNo = result[0].lastNo
    deleteLastDQueryParms.value.lastNo = result[0].lastNo
    LastStyleQueryMethods()
    SizeQueryMethods()
  }
  isLoading.value = false
}

onMounted(() => {
  LastDataQueryMethods()
})

const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入楦头号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '选择型体'
  },
  {
    type: 'button',
    checkboxLabel: '取指令号码明细'
  }
])

// 表格数据

const tableHeader = ref([
  {
    label: '楦头号',
    prop: 'lastNo'
  },
  {
    label: '鞋垫前后缀',
    prop: 'tech1'
  },
  {
    label: '底长',
    prop: 'tech2'
  },
  {
    label: '掌宽',
    prop: 'tech3'
  },
  {
    label: '跟宽',
    prop: 'tech4'
  },
  {
    label: '掌围',
    prop: 'tech5'
  },
  {
    label: '腰围',
    prop: 'tech6'
  },
  {
    label: '背围',
    prop: 'tech7'
  },
  {
    label: '楦头后跟高',
    prop: 'tech8'
  },
  {
    label: '楦头头翘',
    prop: 'tech9'
  }
])

// 表格数据
const tableHeader1 = ref([
  {
    label: '型体',
    prop: 'style'
  }
])

const tableHeader2 = ref([
  {
    label: '号码',
    prop: 'sizeNo'
  }
])

const tableHeader3 = ref([
  {
    label: '型体',
    prop: 'style'
  }
])
</script>

<style lang="less" scoped>
.ProductionDynamicMainCardMain {
  display: flex;
  // justify-content: space-between;
}

.H1Size {
  font-size: 16px;
  justify-content: space-between;
}

.bottom {
  float: right;
  margin-top: 10rem;
}

.ProductionDynamicMainCardMain {
  display: flex;
}
</style>
